/**
 * Copyright (c) 华南农业大学信息学院蔡超敏2015版权所有
 * 
 * 文件创建时间：2015年4月6日
 */
package org.scauinfo.fpos.service.impl;

import java.io.Serializable;
import java.util.List;

import org.scauinfo.fpos.dao.impl.ProductTypeDao;
import org.scauinfo.fpos.service.ProductTypeService;
import org.scauinfo.fpos.vo.ProductType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * @author 蔡超敏
 * 
 */
@Repository
public class ProductTypeServiceImpl implements ProductTypeService {

	@Autowired
	private ProductTypeDao productTypeDao;

	@Override
	public void saveProductType(ProductType productType) {
		productTypeDao.save(productType);
	}

	@Override
	public void updateProductType(ProductType productType) {
		productTypeDao.update(productType);
	}

	@Override
	public void deleteProductType(int id) {
		ProductType productType = productTypeDao.get(id);
		productType.setProducts(null);
		productTypeDao.delete(productType);
	}

	@Override
	public List<ProductType> findAllProductType(int page, int rows,
			String sort, String order) {
		return productTypeDao.findAll(page, rows, sort, order);
	}

	@Override
	public int getTotal() {
		return productTypeDao.countAll();
	}

	@Override
	public boolean isExist(String productTypeId) {
		boolean flag = false;
		String hql = "from ProductType as p where p.productTypeId="
				+ productTypeId;
		if (productTypeDao.find(hql).size() > 0) {
			flag = true;
		}
		return flag;
	}

	@Override
	public List<ProductType> findAllProductType() {
		return productTypeDao.findAll();
	}

	@Override
	public ProductType get(Serializable id) {
		return productTypeDao.get(id);
	}

}
